﻿using System;

namespace ShuttleBus.Transports.Msmq
{
    internal class MsmqEndpoint : Endpoint, IMsmqEndpoint
    {
        private readonly Func<IQueue> _factory;
        private IQueue _queue;

        public MsmqEndpoint(Uri uri, Func<IQueue> factory)
            : base(uri)
        {
            _factory = factory;
        }

        public override string Path
        {
            get
            {
                return Uri.ToMsmqPath();
            }
        }

        public override IQueue Initialize(QueueMode mode)
        {
            return _queue ?? (_queue = _factory());
        }
    }
}